package com.googlecode.mvchat.client;

import java.net.Socket;
import java.util.ArrayList;

import org.apache.commons.lang3.ArrayUtils;

public class MessageThread extends Thread {

	private Socket s;
	public MessageThread(Socket s){
		this.s=s;
	}

	public void run(){
		while(true){
			try{
				int b;
				ArrayList<Byte> byteList = new ArrayList<Byte>();
				while((b = s.getInputStream().read()) != ((int)'\n')){
					byteList.add((byte)b);
				}
				Byte[] byteArr = new Byte[byteList.size()];
				byteList.toArray(byteArr);

				Main.onRecieve(ArrayUtils.toPrimitive(byteArr));
			} catch(Exception e){

			}
		}
	}
}
